package com.main.ok.push;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.greenline.push.services.PushCenterCommonService;

public class EchatTest {

    static ExecutorService eService = Executors.newFixedThreadPool(10);

    public static void main(String[] args) {
        // String echatString =
        // "{\"content\":\"{\"context\":\"{\\\"message\\\":\\\"用户预约了您今日 (周四) 17:00的电话咨询，点击查看详情。\\\",\\\"orderId\\\":461,\\\"orderStatus\\\":1,\\\"payStatus\\\":1,\\\"title\\\":\\\"医生咨询\\\"}\",\"date\":1427941286641,\"media\":\"3\",\"module\":\"consult_status_change_msg\"}\"}";
        String echatString="{\"context\":\"{\\\"consultId\\\":264,\\\"message\\\":\\\"您的一个免费视频订单已失效\\\",\\\"type\\\":3,\\\"userId\\\":182947,\\\"userType\\\":0}\",\"date\":1422601860067,\"media\":\"3\",\"module\":\"push_video_consult_app\"}";
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

        /**
         * dubbo服务获取
         */
        PushCenterCommonService pushService = (PushCenterCommonService) ctx.getBean("pushService");
        Map<String, String> params = new HashMap<String, String>();
        params.put("content", echatString);
        // ResponseDTO<Boolean> s = pushService.send(9876543210l,
        // "echatCommonPushTemplate", "echat_relative_domain", params, null);
        /**
         * invoke method
         */
        for (int i = 0; i < 1; i++) {
            eService.execute(new runInvokeEchatService(pushService, params, (long) i));
        }

        eService.shutdown();
        while (!eService.isTerminated()) {
        }

        System.err.println("-----all over-----");
    }

}

class runInvokeEchatService implements Runnable {
    private PushCenterCommonService pushService;
    private Map<String, String> params;
    private Long receiveId;

    public runInvokeEchatService(PushCenterCommonService pushService, Map<String, String> params, Long receiveId) {
        this.pushService = pushService;
        this.params = params;
        this.receiveId = receiveId;
    }

    @Override
    public void run() {
        // TODO Auto-generated method stub
//        pushService.send(5554133l, "echatCommonPushTemplate", "echat_relative_domain", params, null);
        pushService.send(5554133l, "echatCommonPushTemplate", "p_guizhou_domain", params, null);
        // System.out.println(Thread.currentThread().getName());
    }
}
